package com.dlc.felear.xiaoensale.dlc_serial_port;

import android.text.TextUtils;

import com.dlc.felear.xiaoensale.utils.MyLog;

/**
 * 串口相关入口
 * Created by felear on 2018/8/4.
 */

public class DlcSerialPortClient {

    private static final String TAG = "DlcSerialPortClient";

    private static final DlcSerialPortClient ourInstance = new DlcSerialPortClient();

    public static DlcSerialPortClient getInstance() {
        return ourInstance;
    }

    private DlcSerialPortClient() {

    }

    public void clearCmdData(){
        ourInstance.clearCmdData();
    }



    /**
     * 添加端口连接
     *
     * @param port     串口名称
     * @param baudRate 串口波特率
     * @param event    androidEventBus回调Event
     */
    public void addPort(String port, int baudRate, String event) {
        MyLog.e(TAG, "addPort port=" + port + " baudRate=" + baudRate + " event=" + event);
        if (!TextUtils.isEmpty(port) && port.contains("/dev/tty")) {
            SerialPortControl.addSerialPort(port, baudRate, event,80);
        }
    }
    public void addPort(String port, int baudRate, String event,int waitDelay) {
        MyLog.e(TAG, "addPort port=" + port + " baudRate=" + baudRate + " event=" + event);
        if (!TextUtils.isEmpty(port) && port.contains("/dev/tty")) {
            SerialPortControl.addSerialPort(port, baudRate, event,waitDelay);
        }
    }

    /**
     * 发送指令
     *
     * @param port   端口号
     * @param orders 指令内容
     */
    public void send(String port, byte[] orders) {
        SerialPortControl.sendData(port, orders);
    }

}
